<?php

/*
 * Action 5$
 *
 * Look on the top 4 cards of your deck, choose one: Put them into your hand, or discard them and +3 cards
 * When you trash this, gain a cheeper card
 */

class Catacombs extends Card implements iAction, iKingdom, iDarkAges {

    public function __construct() {
        parent::__construct("Catacombs", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Look on the top 4 cards of your deck, choose one: Put them into your hand, or discard them and +3 cards",
            "When you trash this, gain a cheeper card");
    }

    public function trash(Game $game, $name) {
        $price = $this->getPrice($game);
        $price = $price->add(-1);
        $optional_cards = $game->getBoardCardsByPrice(new Price(), $price->getCoins());
        if (sizeof($optional_cards) > 0) {
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $optional_cards, 1, 1, null, "Choose a card to gain", $name);

            $new_card_name = $output[0];
            $new_card = $game->moveCardFromPileToPile($new_card_name, BoardCards, DiscardPile, $name);
            ScreenDisplay::addScreenMessage($game, true, "gain " . nicePrint($new_card), "gains " . nicePrint($new_card), $name);
        }
        $game->setTempCard($this);
        $game->cardTrashFinished($name);
    }

    public function play(Game $game, $isRealCard) {
        $cards = $game->removeCardsFromDrawDeck(4);

        if (sizeof($cards) > 0) {

            $options = array(new Option(1, "Put in hand"), new Option(2, "Discard"));

            ScreenDisplay::addScreenMessage($game, true, "peek on " . nicePrint($cards), "peeks on " . sizeof($cards) . " cards");
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "You peek on " . niceReadableString($game, $cards) . " what would you like to do?");
            $answer = $output[0];

            if ($answer == "Discard") {
                $game->discardTempDiscardCards($cards);
                ScreenDisplay::addScreenMessage($game, false, ", discard them", ", discards them");
                $drawed_cards = $game->drawCards(3);
                ScreenDisplay::addScreenMessage($game, false, " and draw " . nicePrint($drawed_cards), " and draws " . sizeof($drawed_cards) . " cards");
            } else {
                $game->putCardsInPlayHand($cards);
                ScreenDisplay::addScreenMessage($game, false, " and put them in hand.", " and puts them in hand");
            }
        }
        $game->cardActionFinished();
        return true;
    }

}

?>